package bai.publicwelfare_backend.exception;

import lombok.Getter;

@Getter
public enum ErrorCode {

    // ===== JWT 相关错误 =====
    TOKEN_EXPIRED(401, "A0421", "Token已过期"),
    TOKEN_TAMPERED(401, "A0422", "Token被篡改"),
    TOKEN_MISSING(401, "A0423", "Token缺失"),
    TOKEN_INVALID(401, "A0424", "Token无效"),
    TOKEN_TYPE_INVALID(401,"A403001", "令牌类型不正确"),
    REFRESH_TOKEN_INVALID(401, "A040103","refreshToken无效"),

    // ===== 4xx 用户客户端错误 =====
    BAD_REQUEST(400, "A0400", "请求参数错误"),
    USERNAME_EXISTS(400, "A0410", "用户名已存在"),
    UNAUTHORIZED(401, "A0401", "未授权访问"),
    NO_AUTH_ERROR(403, "A0421", "只能修改自己的用户名"),
    FORBIDDEN(403, "A0403", "权限不足"),
    USER_NOT_FOUND(401, "A0411", "用户名不存在"),       // 和密码错误分开提示更安全
    PASSWORD_ERROR(401, "A0412", "密码错误"),          // 不提示"用户名或密码错误"这种模糊信息
    ACCOUNT_LOCKED(403, "A0413", "账户已锁定"),        // 多次失败后锁定
    LOGIN_LIMIT(429, "A0414", "此账号登录尝试过多，请稍后再试"), // 限流专用
    CAPTCHA_ERROR(400, "A0415", "验证码错误"),         // 如果需要验证码功能
    ACCOUNT_DISABLED(403, "A0416", "账户已禁用"),       // 管理员手动禁用

    // ===== 5xx 服务端错误 =====
    INTERNAL_ERROR(500, "B0500", "系统内部错误"),
    SERVICE_UNAVAILABLE(503, "B0503", "服务不可用"),

    // ===== 活动模块错误码（4xx客户端错误）=====
    EVENT_NOT_FOUND(404, "A0501", "活动不存在"),
    EVENT_STATUS_INVALID(400, "A0502", "活动已结束或已取消"),
    PARTICIPATION_DUPLICATE(400, "A0503", "您已参与该活动"),
    PARTICIPATION_LIMIT(400, "A0504", "参与人数已达上限"), // 如果需要检查人数上限

    // ===== 积分模块错误码（4xx客户端错误）=====
    BADGE_ALREADY_OWNED(400, "A0506", "已拥有此勋章"),
    POINTS_NOT_ENOUGH(400, "A0505", "积分不足");



    private final int httpStatus;  // HTTP状态码
    private final String code;     // 业务错误码（A0400/B0500格式）
    private final String defaultMsg; // 默认错误信息

    // 构造器
    ErrorCode(int httpStatus, String code, String defaultMsg) {
        this.httpStatus = httpStatus;
        this.code = code;
        this.defaultMsg = defaultMsg;
    }
}
